package com.yssoft.controller.supervise;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yssoft.controller.BaseController;
import com.yssoft.service.core.AreaService;
import com.yssoft.service.publicPlatform.PublicTraceService;
import com.yssoft.service.purchase.RecipientDetailService;
import com.yssoft.service.supervise.PurchaseStatisticsService;

/**
 * @类名称: PurchaseStatisticsController
 * @类描述: 采购统计控制器
 * @作者:洪丰
 * @创建时间:2018年6月8日 下午3:48:53
 */
@Controller
@RequestMapping(value = "/purchaseStatistics")
public class PurchaseStatisticsController extends BaseController
{
	@Resource
	private RecipientDetailService recipientDetailService;
	@Resource
	private PublicTraceService publicTraceService;
	@Autowired
	private PurchaseStatisticsService purchaseStatisticsService;
    @Resource
    private AreaService areaService;
    
	/**
	 * @方法名称: list
	 * @功能描述: 跳转到采购统计页面
	 * @作者: 洪丰
	 * @创建时间:2018年6月8日 下午3:51:43
	 * @param model
	 * @return String
	 */
	@RequestMapping(value = "/list")
	public String list(Model model){
		String areaTree = areaService.queryAreaTree();
        model.addAttribute("areaTree", areaTree);
		return "supervise/purchaseStatistics/purchaseStatisticsList";
	}
	

	/**
	 * @方法名称: findProductPage
	 * @功能描述: 获取采购统计列表页
	 * @作者: 洪丰
	 * @创建时间:2018年6月8日 下午3:56:40
	 * @param page
	 * @param limit
	 * @param productName
	 * @return JSONObject
	 */
	@RequestMapping("/findPage")
    @ResponseBody
    public JSONObject findPage(@RequestParam(name = "page",defaultValue = "0") int page 
    		, @RequestParam(name = "limit",defaultValue = "10") int limit, String purchaseDate
    		, String entIds, Integer areaId, String mClassily, String sName){
        JSONObject jsonObject = purchaseStatisticsService.queryPage(page, limit, purchaseDate
        		, entIds, areaId, mClassily, sName);
        return jsonObject;
    }
	
	/**
	 * @方法名称: toRecipient
	 * @功能描述: 跳转到收货详情页面
	 * @作者: 洪丰
	 * @创建时间:2018年6月12日 下午3:37:31
	 * @param model
	 * @param purDetailId
	 * @return String
	 */
	@RequestMapping(value = "/toRecipient")
	public String toRecipient(Model model, Integer purDetailId){
        model.addAttribute("purDetailId", purDetailId);
		return "supervise/purchaseStatistics/recipientList";
	}
	
	/**
	 * @方法名称: toRecipient
	 * @功能描述: 获取收货详情数据
	 * @作者: 洪丰
	 * @创建时间:2018年6月12日 下午3:37:31
	 * @param model
	 * @param purDetailId
	 * @return String
	 */
	@RequestMapping("/findRecipient")
    @ResponseBody
    public JSONObject findRecipient(Integer purDetailId){
        JSONObject jsonObject = purchaseStatisticsService.queryRecipient(purDetailId);
        return jsonObject;
    }
	
	/**
	 * @方法名称: toInspection
	 * @功能描述: 跳转到检验报告页面
	 * @作者: 洪丰
	 * @创建时间:2018年6月13日 上午11:34:08
	 * @param model
	 * @param inspectionId
	 * @return String
	 */
	@RequestMapping(value = "/toInspection")
	public String toInspection(Model model, Integer recipientId){
        model.addAttribute("recipientId", recipientId);
		return "supervise/purchaseStatistics/inspectionList";
	}
	
	/**
	 * @方法名称: findInspectionPage
	 * @功能描述: 获取检验报告列表
	 * @作者: 洪丰
	 * @创建时间:2018年6月13日 上午11:32:51
	 * @param page
	 * @param limit
	 * @param recipientId
	 * @return JSONObject
	 */
	@RequestMapping("/findInspectionPage")
    @ResponseBody
    public JSONObject findInspectionPage(@RequestParam(name = "page",defaultValue = "0") int page 
    		, @RequestParam(name = "limit",defaultValue = "10") int limit, Integer recipientId){
        JSONObject jsonObject = purchaseStatisticsService.queryInspectionPage(page, limit, recipientId);
        return jsonObject;
    }
	
	/**
	 * @方法名称: toTraceGather
	 * @功能描述: 跳转到溯源信息页面
	 * @作者: 洪丰
	 * @创建时间:2018年6月13日 下午1:45:08
	 * @param recipientId
	 * @param model
	 * @return String
	 */
	@RequestMapping(value = "/toTraceGather")
	public String toTraceGather(Integer recipientId,Model model){
		 List<Map<String, Object>> technologyList = publicTraceService.findTechnologyByRecipientId(recipientId+"");
	      for (Map<String, Object> stringObjectMap : technologyList) {
	          List<Map<String, Object>> index = recipientDetailService.findIndexAndValueByProcessingTechnic(stringObjectMap.get("id") + "",recipientId+"");
	          stringObjectMap.put("technicIndex", index);
	      }
	      model.addAttribute("technologyList", technologyList) ;   
	/*	List<Map<String,Object>> straceProcessList = purchaseStatisticsService.queryTraceGather(recipientId);*/
		//model.addAttribute("straceProcessList", straceProcessList);
		return "supervise/purchaseStatistics/traceGatherList";
	}
}
